package com.ylr.basic.framework.service.impl;

import com.ylr.basic.framework.entity.AesOperateFlowEntity;
import com.ylr.basic.framework.mapper.AesOperateFlowMapper;
import com.ylr.basic.framework.service.AesOperateFlowService;
import com.ylr.base.common.enums.CommonEnum;
import com.ylr.base.framework.service.SnowflakeService;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2023-04-27 22:17:30
 * className: AesOperateFlowServiceImpl aes加解密操作记录服务接口实现类
 * version: 1.0
 * description:
 */
@Service("aesOperateFlowService")
@AllArgsConstructor
public class AesOperateFlowServiceImpl extends ServiceImpl<AesOperateFlowMapper, AesOperateFlowEntity> implements AesOperateFlowService {

    private static final Logger log = LoggerFactory.getLogger(AesOperateFlowServiceImpl.class);

    private final SnowflakeService snowflakeService;

    @Override
    public void saveFlow(Integer module, Integer type, String result, String requestId, String remark, String createUser, Long createUserId) {

        Date date = new Date();
        // 1、对象构造
        AesOperateFlowEntity aesOperateFlow = new AesOperateFlowEntity();
        aesOperateFlow.setId(snowflakeService.getId())
                .setModule(module)
                .setType(type)
                .setResult(result)
                .setRequestId(requestId)
                .setRemark(remark)
                .setDeleteStatus(CommonEnum.DELETE_NO.getValue())
                .setDeleteTime(date)
                .setDeleteUser(StringUtils.EMPTY)
                .setDeleteUserId(CommonEnum.DEFAULT_ID.getLongValue())
                .setCreateTime(date)
                .setCreateUser(createUser)
                .setCreateUserId(createUserId);
        // 2、插入数据
        baseMapper.insert(aesOperateFlow);
        log.info("aes操作流水插入完成");
    }
}